import { ref } from 'vue'
import { adapter, request } from '@/request'
import { orderScheduleStatusByPost } from '@/core/api/order'
import type { RequestWrapper } from '@/core/interfaces/common'
import type { ServiceStatusEnum } from '@/core/enums/status'

export interface ScheduleStatusParams {
  id?: number
  orderWordId: number
  weekNo: number
  serviceStatus: ServiceStatusEnum
}

export default function updateOrderScheduleStatus() {
  const service = adapter<RequestWrapper<ScheduleStatusParams>>(request)
  const loading = ref(false)
  const response = ref<Partial<ScheduleStatusParams>>({})

  const fetch = (data: ScheduleStatusParams) => {
    const { url, method } = orderScheduleStatusByPost()
    loading.value = true

    return service({
      config: {
        url,
        method,
        data
      },
      callback: (res) => {
        response.value = res.data.data
      },
      error: (err) => {
        console.log(err)
      },
      done: () => {
        loading.value = false
      }
    })
  }

  return [response, fetch, loading] as const
}
